﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Chemical.Model;
using Yipusoft.Chemical.BLL;
using Yipusoft.Common.Model;
using Yipusoft.Common.BLL;

public partial class BasicBase_Chemical_ChemicalList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            init();
        }
    }

    void init()
    {
        if (Request.QueryString["where"] != null)
        {
            lblwhere.Text = Request.QueryString["where"];
            Bind(0);
            topmenu.Visible = false;
            gvChemical.Columns[4].Visible = false;
            gvChemical.Columns[5].Visible = false;
        }
        else
        {
      
            gvChemical.Columns[6].Visible = false;
        }
    }

    protected void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        Bind(PageIndex);
    }
    protected void lbtQurey_Click(object sender, EventArgs e)
    {
        if (txtChemicalName.Text.Trim() != "")
        {
            lblwhere.Text = ddlNameType.SelectedValue + " like '%" + txtChemicalName.Text + "%'";
        }
        else
        {
            lblwhere.Text = "";
        }
        ListPageContral1.SetFirstPage();
        Qurey();
    }

    void Qurey()
    {
        if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "201600") || Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "201601"))
        {
            Bind(0);
        }
        else
        {
            Response.Write("<script>alert('没有权限！');history.back(0);</script>");
            return;
        }
    }

    void Bind(int pageIndex)
    {
        ListPageContral1.ItemCount = Chemical.GetCount(lblwhere.Text);
        gvChemical.DataSource = Chemical.GetListSliptPage(ListPageContral1.PageSize, pageIndex, lblwhere.Text);
        gvChemical.DataBind();
    }
    protected void gvChemical_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblID = e.Row.FindControl("lblID") as Label;
            lblID.Text = Convert.ToString(gvChemical.PageSize * ListPageContral1.CurrentPageIndex + (e.Row.RowIndex + 1));
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }
    protected void gvChemical_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Del")
        {
            #region 权限
            bool isPermission = false;
            if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "201600"))
            {
                isPermission = true;
            }
            else
            {

                if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "201605"))
                {
                    isPermission = true;
                }

            }
            if (!isPermission)
            {
                Response.Write("<script>alert('没有权限！');history.back(0);</script>");
                return;
            }
            #endregion
            Chemical.Delete(e.CommandArgument.ToString());
            EventLogInfo log = new EventLogInfo();
            log.EventTime = DateTime.Now;
            log.EventType = 1;
            log.EventData = "删除一个化危品";
            log.ItemID = e.CommandArgument.ToString();
            log.ItemName = "BasicBase";
            log.ItemFullUrl = "Chemical/ChemicalList";
            log.CreatedBy = Context.User.Identity.Name;
            log.CreatedTime = DateTime.Now;
            log.UserIP = Request.UserHostAddress;
            EventLog.Insert(log);
            Prompt.Text = "提示:删除成功!";
            Bind(0);
        }
    }
}
